package com.gwtcx.server.dao;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.gwtcx.server.domain.User;

public class UserDaoFirst {
	@Inject
	private Provider<EntityManager> em;
	
	public String createUser(User user) {
   		em().persist(user);
   		return user.getLogin();
	}

	public User retrieveUser(String login) {
    	TypedQuery<User> query = em().createQuery("select u from User u where u.login = ?1", User.class);
	    query.setParameter(1, login);
	    return query.getSingleResult();
	}
	
	private EntityManager em() {
		return em.get();
	}
}
